﻿Imports Mysoft.Map.Data

Partial Class SelectUser3
    Inherits Mysoft.Map.Application.Security.AppPage

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not IsPostBack Then

            '公司GUID，用于过滤带选择单位
            Dim strBUGUID As String = Request.QueryString("buguid")
            '部门GUID,用于过滤待选用户范围
            Dim strDeptGUID As String = Request.QueryString("DeptGUID")

            Dim strSQL As String

            If strBUGUID Is Nothing Then strBUGUID = ""

            Dim strFilter As String = ""

            If Not strDeptGUID Is Nothing Then
                strFilter = " AND ( a.BUGUID = '" & strDeptGUID & "'  ) "
            End If

            If Not Request.QueryString("MyFyys") Is Nothing And Request.QueryString("MyFyys") = "RCBX" Then  '控制公司显示级数.集团2级 公司1级
                '日常报销的
                If strBUGUID = "" Then
                    strSQL = " SELECT HierarchyCode AS code,BUGUID AS guid,BUName AS name,companyguid,butype" & _
                          " FROM  vys_myBusinessUnit " & _
                          " WHERE (1=1) " & _
                          " ORDER BY OrderHierarchyCode"
                Else
                    strSQL = " SELECT a.HierarchyCode AS code,BUGUID AS guid,BUName AS name,a.companyguid,a.butype" & _
                          " FROM vys_myBusinessUnit a " & _
                          " WHERE (1=1) " & _
                          "  AND  a.CompanyGUID='" & strBUGUID & "'" & _
                          " ORDER BY a.OrderHierarchyCode"
                End If
            Else
                '事项编辑
                If strBUGUID = "" Then
                    strSQL = " SELECT HierarchyCode AS code,BUGUID AS guid,BUName AS name,companyguid,butype" & _
                          " FROM  vys_myBusinessUnit " & _
                          " WHERE (1=1) " & _
                          " ORDER BY OrderHierarchyCode"
                Else
                    strSQL = " SELECT a.HierarchyCode AS code,BUGUID AS guid,BUName AS name,a.companyguid,a.butype" & _
                          " FROM vys_myBusinessUnit a " & _
                          " WHERE (1=1) " & _
                          " " & strFilter & " " & _
                          "  AND  a.CompanyGUID='" & strBUGUID & "'" & _
                          " ORDER BY a.OrderHierarchyCode"
                End If

            End If
            repBU.BindMode = 1
            repBU.DataTable = MyDB.GetDataTable(strSQL)
            repBU.DataBind()

            '传入的单位
            txtCurBUCode.Text = ""
            If strDeptGUID <> "" Then
                strSQL = "SELECT HierarchyCode FROM myBusinessUnit WHERE BUGUID='" & strDeptGUID & "'"
                txtCurBUCode.Text = MyDB.GetDataItemString(strSQL)
            End If
            '默认显示当前单位下的用户
            appGrid.CustomFilter = "a.HierarchyCode ='" + txtCurBUCode.Text + "'"

            '绑定已选择用户
            Dim strSelectedUser As String = Request.QueryString("SelectedUser")
            If strSelectedUser Is Nothing OrElse strSelectedUser = "" Then
                appGrid2.CustomFilter = "1=2"
            Else
                appGrid2.CustomFilter = "UserGUID in ('" & strSelectedUser.Replace(",", "','") & "')"
                txtUserGUIDList.Text = strSelectedUser
            End If

            Dim strMultiSelect As String = Request.QueryString("MultiSelect")
            If strMultiSelect = "1" Then
                Tr1.Attributes.Item("style") = "display:"
                Tr2.Attributes.Item("style") = "display:"
                Tr3.Attributes.Item("style") = "display:"
                appGrid.MultiSelect = True
                txtMultiSelect.Text = "1"
            Else
                Tr1.Attributes.Item("style") = "display:none"
                Tr2.Attributes.Item("style") = "display:none"
                Tr3.Attributes.Item("style") = "display:none"
                appGrid.MultiSelect = False
                txtMultiSelect.Text = "0"
            End If

            '控制是否需要清空功能
            Dim strAllowClear As String = Request.QueryString("AllowClear")
            If strAllowClear = "1" Then
                btnClear.Visible = True
            Else
                btnClear.Visible = False
            End If

        End If
    End Sub



End Class
